package com.ruibang.glass.equipment.controller;


import com.alibaba.nacos.common.utils.CollectionUtils;
import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.ScrapReport;
import com.ruibang.glass.equipment.service.ScrapReportService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
/**
 * <p>
 *报废报表
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/scrap/report")
@Api(value = "报废报表")
public class ScrapReportController {
    @Autowired
    private ScrapReportService scrapReportService;

    @PostMapping("list")
    @ApiOperation(value = "报废报表列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody DeviceAllPageReq deviceAllPageRea) {
        return ResultBody.success(scrapReportService.getBoilerList(deviceAllPageRea));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加", response = ResultBody.class)
    public ResultBody addChild(@RequestBody ScrapReport scrapReport) {
        return ResultBody.success(scrapReportService.updateOrAddById(scrapReport));
    }


    //
    @PostMapping("deleteAll")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteAll(@RequestBody ScrapReport scrapReport) {
        if (CollectionUtils.isNotEmpty(scrapReport.getIds())) {
            scrapReportService.lambdaUpdate().set(ScrapReport::getIsDelete, Constants.ONE_STR).in(ScrapReport::getId, scrapReport.getId()).update();
        }
        if (StringUtils.isNoneBlank(scrapReport.getId())) {
            scrapReportService.lambdaUpdate().set(ScrapReport::getIsDelete, Constants.ONE_STR).eq(ScrapReport::getId, scrapReport.getId()).update();
        }
        return ResultBody.success();
    }


    @PostMapping("getOne")
    @ApiOperation(value = "查看详情", response = ResultBody.class)
    public ResultBody getOne(@RequestBody ScrapReport scrapReport) {
        return ResultBody.success(scrapReportService.getById(scrapReport.getId()));
    }


    @PostMapping("insertById")
    @ApiOperation(value = "新增", response = ResultBody.class)
    public ResultBody insertById(@RequestBody ScrapReport scrapReport) {
        scrapReportService.insertById(scrapReport);
        return ResultBody.success();
    }


    @PostMapping("/export")
    @ApiOperation(value = "数据导出", response = ResultBody.class)
    public void export(@RequestBody DeviceAllPageReq deviceAllPageRea, HttpServletResponse response) {
        scrapReportService.export(deviceAllPageRea, response);
    }

}
